home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / GapText.h < prev    next >
C/C++ Source or Header  |  1992-08-26  |  4KB  |  135 lines

  1. #ifndef GapText_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define GapText_First
  7.  
  8. #include "Text.h"
  9.  
  10. //---- class GapText ------------------------------------------------------
  11.  
  12. typedef class GapText *GapTextPtr;
  13.  
  14. extern char *cMemOverflow;
  15. extern char *cGapTextName;
  16.  
  17. class GapText: public Text  { 
  18. public:
  19.     MetaDef(GapText);
  20.  
  21.     GapText(int s= 16, Font *fd= gSysFont);
  22.     GapText(byte *buf, int len= -1, Font *fd= gSysFont);
  23.     ~GapText();
  24.     void InitNew();
  25.  
  26.     //---- editing
  27.     void CopyInStr(byte *str,int strsize,int from, int to);
  28.     void ReplaceRange(int from, int to, Text *tsrc, int sfrom, int sto);
  29.  
  30.     //---- accessing
  31.     byte& operator[](int i);
  32.     int Size();
  33.     int Search(class RegularExp *rex,int *nMatched, int start= 0, 
  34.            int range= cMaxInt, bool dir= cSearchForward);
  35.  
  36.     //---- iterators
  37.     TextIter *MakeIterator(int from = 0, int to = cMaxInt);
  38.  
  39.     //---- TextPainter access
  40.     byte *GetLineAccess(byte **buf, int from, int to);
  41.     
  42.     //---- TextReader access
  43.     void AddChar(int at, byte b);
  44.     
  45.     //---- input/output
  46.     OStream& PrintOn(OStream&);
  47.     IStream& ReadFrom(IStream&);
  48.     OStream& PrintOnAsPureText(OStream &s);
  49.     IStream& ReadFromAsPureText(IStream&, long sizeHint= -1);
  50.  
  51. protected:
  52.     byte CharAt(int i);
  53.     void Terminate();
  54.     Text *MakeScratchText(byte *buf, int size); 
  55.     
  56. private: 
  57.     friend class GapTextIter;
  58.  
  59.     int size;                               // size of allocated memory
  60.     int length;                             // length of text
  61.     int part1len;                           // length of text before gap
  62.     int part2len;                           // redundant
  63.     int gaplen;                             // length of gap
  64.     byte *body;                             // access to text befor gap
  65.     byte *part2body;                        // access to text behind gap
  66.     byte *body2;                            // redundant
  67.  
  68.     void Update(int l);
  69.     void Init(int l, Font *fd);
  70.     void Expand(int to = 0, int moveto = cMaxInt);
  71.     void Shrink(int to = 0);
  72.     void MoveGap(int to);
  73.     void CopyTo(byte *dst, int from, int to);
  74.     bool HighWaterMark(int n);
  75.     bool LowWaterMark();
  76.     void CheckPtr(byte *ptr);
  77. };
  78.  
  79. inline bool GapText::HighWaterMark(int n)
  80.     return  body == 0 || gaplen <= n; 
  81. }
  82.  
  83. inline bool GapText::LowWaterMark()
  84.     return size / 5 > length;
  85. }
  86.  
  87. inline byte GapText::CharAt(int i)
  88.     return (i < part1len ? body : part2body)[i]; 
  89. }
  90.  
  91. //---- class GapTextIter -------------------------------------------------
  92.  
  93. class GapTextIter: public TextIter {
  94.     int nextFontChange;
  95.     byte escape;
  96.     GapText *st;
  97.     CharStyle *sp;
  98.  
  99.     bool TestFontChange(int at, CharStyle *&sp);
  100.     int GraphicSize(int at, LineDesc *l);
  101.     byte CharAt(int i);
  102.     bool TestFontChange(CharStyle *&sp);
  103.     bool TestVisualMark(int at, int ch);
  104. public:
  105.     GapTextIter(Text *s, int from= 0, int to= cMaxInt);
  106.     void Reset(Text *s, int from= 0, int to= cMaxInt);        
  107.     int operator()(int *width= 0, LineDesc *ld= 0);
  108.     int Token(int *width, LineDesc*); // returns next token with its extent
  109. };
  110.  
  111. inline byte GapTextIter::CharAt(int i)
  112.     return st->CharAt(i); 
  113. }
  114.  
  115. inline bool GapTextIter::TestFontChange(CharStyle *&sp)
  116.     if (ce == nextFontChange) {
  117.     nextFontChange= st->GetNextFontChange(ce, sp);
  118.     return TRUE;
  119.     }
  120.     else 
  121.     return FALSE;
  122. }
  123.  
  124. inline bool GapTextIter::TestVisualMark(int at, int ch)
  125.     return (bool) (ch == escape && st->IsVisualMark(at)); 
  126. }
  127.  
  128. #endif    
  129.